package com.heima.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HelloController {

    @Resource
    private KafkaTemplate<String,String> template;

    @GetMapping("/hello")
    public String hello(){
//        template.send("topic","我是一个兵");
        User user = new User();
        user.setUsername("wuwei");
        user.setAge(18);
        String string = JSON.toJSONString(user);
        template.send("user-topic",string);
        return "OK";
    }
}
